package com.monas.client.jfree;

import java.awt.Font;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;

public class MonasPieChart extends AbstractMonasChart {

	public MonasPieChart(String title) {
		super(title, null, null);

		dataSet = new DefaultPieDataset();
	}

	@Override
	public void createChart() {
		chart = ChartFactory.createPieChart(title, // chart title
				(DefaultPieDataset) dataSet, // data
				true, // include legend
				true, false);

		PiePlot plot = (PiePlot) chart.getPlot();
		plot.setSectionOutlinesVisible(false);
		StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(
				"{0} = {1} ({2})");
		plot.setLabelGenerator(labelGen);

		// Font
		plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
		plot.setNoDataMessage("No data available");
		plot.setCircular(false);
		plot.setLabelGap(0.02);
	}

	public void addValue(String label, Number value) {
		((DefaultPieDataset) dataSet).setValue(label, value);
	}

	public void setTitle(String title) {
		chart.setTitle(title);
	}

	@Override
	public void clearData() {
		((DefaultPieDataset) dataSet).clear();
	}

	@Override
	protected int getWidth() {
		return 500;
	}

	@Override
	protected int getHeight() {
		return 400;
	}

}
